import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'messagePage.dart';
import 'dynamicPage.dart';
import 'contactsPage.dart';
import 'smallWorld.dart';
import 'myPage.dart';
class mainPage extends StatefulWidget{
  @override
  mainPageState createState() => mainPageState();
}

class mainPageState extends State<mainPage>{
  var allPages=[messagePage(),contactsPage(),smallWorld(),dynamicPage()];
  var currentIndex=0;
  var Name = '';
  var qqpic = ''; // qq头像
  get() async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    Name = prefs.getString("QQ").toString();
    qqpic = prefs.getString("Pic").toString();
    print('qqpic:${qqpic}');
  }
  @override
  void initState() {
    // TODO: implement initState
    get();
    super.initState();
  }
  @override
  Widget build(BuildContext context){
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'tencentQQ',
      home: Scaffold(
        body: allPages[currentIndex],
        backgroundColor: Colors.white,
      appBar: AppBar(
        // 头像
        leading: IconButton(
          icon: Container(
            padding: EdgeInsets.all(1.0),
            child: CircleAvatar(backgroundImage: AssetImage(qqpic)),
          ),
          onPressed: (){
            Navigator.of(context)
                .push(MaterialPageRoute(builder: (BuildContext context) {
              return myPage(
                  Name:Name,
                  Pic:qqpic,
              );
            }));
          },
        ),
        // 昵称
        title: Text(Name,style: TextStyle(
          fontSize: 17,
        ),),
        // 右方菜单
        actions: [
          PopupMenuButton(
              child: Container(
                margin: const EdgeInsets.all(5),
                child: Icon(Icons.add),
              ),
              itemBuilder: (context)=>[
                PopupMenuItem(
                  child: const Text('创建群聊'),
                  value: 1,
                  onTap: (){},
                ),
                PopupMenuItem(
                  child: const Text('加好友/群'),
                  value: 2,
                  onTap: (){},
                ),
                PopupMenuItem(
                  child: const Text('扫一扫'),
                  value: 3,
                  onTap: (){},
                ),
                PopupMenuItem(
                  child: const Text('面对面快传'),
                  value: 4,
                  onTap: (){},
                ),
                PopupMenuItem(
                  child: const Text('收付款'),
                  value: 5,
                  onTap: (){},
                ),
              ]
          )
        ],
      ),
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          unselectedItemColor: Colors.grey,
          selectedItemColor: Colors.blue,
          currentIndex: currentIndex,
          items: [
            BottomNavigationBarItem(
                icon: Icon(Icons.message),
                label:"消息"
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.people),
                label:"联系人"
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.camera),
                label:"小世界"
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.star),
                label:"动态"
            ),
          ],
          onTap: (index){
            setState(() {
              print("the index is :$index");
              currentIndex=index;
            });
          },
        ),
      ),
    );
  }
}
